[r815]: / branches / FeatureBranches / Debuglogging / SparkplugB / Function Blocks / FB_PrimaryHost / FB_PrimaryHost / svnobj  Maximize  Restore  History

Download this file

60 lines (59 with data), 16.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(*
    Primary Host Node
    ServerUrl     : STRING;          // eg:'test.mosquitto.org';
    ServerPort    : UINT    := 1883; // eg: 1883
    PrimaryHostID : WSTRING := "";   // eg:'PrimaryHost';
    //  * The client must get all messages from a certain topic, even if it is offline. 
    //  * You want the broker to store the subscription information of the client and restore the interrupted communication quickly.
    //  * The client needs only to publish messages to topics, the client does not need to subscribe to topics. 
    //  * The client does not need to get messages that it misses offline. 
    //
    CleanSession : BOOL    := FALSE;
    Password     : WSTRING := "";           // specify the password for the username (optional)
    ;                                           // Handle to the client certificate (optional) and only used if UseTLS is TRUE
    ITLSContextProvider : MQTT.NBS.ITLSContext
    //Static initialization, as shown in the following code snippet;
    //VAR
    //    commonName : STRING := 'MyRasPi';
    IASyncPropertyProvider : MQTT.NBS.IAsyncProperty; // Runs the connect process in a own background task. Use this property if the connection setup takes longer than one task cycle (e.g. TLS connections)
END_VAR
VAR_OUTPUT
    Connected      : BOOL;
    SessionState   : SparkplugSessionStateType;
    itfPrimaryHost : IPrimaryHost := THIS^;
VAR
    _groupIDs    : List;         // OF FB_GroupID - This is groupIDs with names
    Connect      : BOOL := TRUE
    _cPrimaryHostID : WSTRING;   // Corrected PrimaryHostID, contains no illegal chars    
    _Enabled        : BOOL;
    _ConnectionTime : TIME                := T#30S;
    _LockTimesArray : ARRAY[1..8] OF TIME := [
    _OutTimeRemaining   : TIME;                                       // Duration of Out Time Period = TRUE remaining
    _LockTimeRemaining  : TIME;
    _SparkplugB         : FB_SparkplugBSimple;     // Handles SparkPlugB Stuff 
    _Blob               : ARRAY[0..65535] OF BYTE; // buffer for encoded messages
    _LastWillTopic      : WSTRING(GC_Sparkplug.supported_string_lengths);
    _NDEATHPayload      : ARRAY[0..255] OF BYTE; // what is the maximum size of this payload?
    _NDEATHPayloadSize  : UDINT;
    _RecvMesg           : REFERENCE TO FB_PayloadSimpleDecoder;
// Components
_MQTT.IASyncPropertyProvider( IASyncPropertyProvider );
_MQTT.ITLSContextProvider( ITLSContextProvider );
_MQTT();
    _RecvMesg REF= _MQTT.GetSubscriberMessage(MetricList := THIS^._AllMetricsList, MessageTopic => _RecvTopic );
    onSubscribeMessage( pTopic := ADR( _RecvTopic ),
                        pMessage := _RecvMesg );
END_IF
_ExponentialBackOff( Enable := (Connect AND NOT Connected),
                     ConnectionTime := _ConnectionTime,
                     LockTimesArray := _LockTimesArray,
                     Enabled => _Enabled,
                     OutTimeRemaining => _OutTimeRemaining,
                     LockTimeRemaining => _LockTimeRemaining );
_StateMachine( Connect := _ExponentialBackOff.out,
               PrimaryHostConnected := Connected,
               pMQTT := ADR( _MQTT ),
               pSparkplugB := ADR( _SparkplugB ),
               pPrimaryHost := THIS,
               SessionState => SessionState );
Diag();